import { BaseModel } from '@/common/base/base.model';
import { Column, Entity, Index, JoinColumn, ManyToOne } from 'typeorm';
import { BooleanNumber } from "common/utils/data";
import { EvaluationModel } from "@/module/evaluation/evaluation.model";
import { EvaluationProjectModel } from "@/module/evaluation-project/evaluation-project.model";

@Entity('EVALUATION_DATA', {
  synchronize: false,
}) // 评测项目数据 EVALUATION_PROJECT_DATA 这个名字是最好，先没改
@Index('EVALUATION_DATA.evaluation_uuid&project_uuid&name',
  ['evaluationUuid', 'projectUuid', 'name'],
  {
  unique: true,
})
export class EvaluationDataModel extends BaseModel {
  @Column({
    comment: '评测uuid',
    type: 'uuid',
  })
  evaluationUuid: string;
  @ManyToOne(() => EvaluationModel, {
    createForeignKeyConstraints: false
  })
  @JoinColumn({
    name: 'evaluation_uuid',
    referencedColumnName: 'uuid',
  })
  evaluation: EvaluationModel;

  @Column({
    comment: '评测项uuid',
    type: 'uuid',
  })
  projectUuid: string;
  @ManyToOne(() => EvaluationProjectModel, {
    createForeignKeyConstraints: false
  })
  @JoinColumn({
    name: 'project_uuid',
    referencedColumnName: 'uuid',
  })
  project: EvaluationProjectModel;

  @Column({
    comment: '字符串数据（目前为csv数据，dataSet）',
    type: 'varchar',
    length: 999999,
    default: '',
  })
  data: string;

  @Column({
    comment: '描述',
    type: 'varchar',
    length: 5000,
    default: '',
  })
  desc: string;

  @Column({
    comment: '名称',
    type: 'varchar',
    length: 200,
    default: '',
  })
  name: string;

  @Column({
    comment: '分组',
    type: 'varchar',
    length: 200,
    nullable: true,
    default: null,
  })
  group: string;

  @Column({
    comment: '图片数据',
    type: 'varchar',
    length: 200,
    default: '',
  })
  img: string;

  @Column({
    comment: '默认显示',
    type: 'smallint',
    default: BooleanNumber.true,
  })
  defaultShow: BooleanNumber;

  @Column({
    comment: 'json数据',
    type: 'json',
    default: {},
  })
  json: any;

  @Column({
    comment: '序号',
    type: 'smallint',
    default: 0,
  })
  sort: number;
}
